package com.bw.zhuangao5___day002.Fragment.Movies.One;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 类名： MoviesOne_Okhttp
 * 作者： Android工程师杨晨
 * 日期： 2021/9/28 15:01
 * DAO：  ZhuanGao5___Day002
 */
public class MoviesOne_Okhttp {
    public static MoviesOne_Okhttp moviesOne_okhttp;
    public Retrofit retrofit;
    public static  MoviesOne_Okhttp getMoviesOne_okhttp()
    {
        if (moviesOne_okhttp==null){
            synchronized (MoviesOne_Okhttp.class)
            {
                if (moviesOne_okhttp==null){
                    moviesOne_okhttp = new MoviesOne_Okhttp();
                }
            }
        }
        return moviesOne_okhttp;
    }


    public Retrofit retrofit(String name){
        if (retrofit==null){
            synchronized (Retrofit.class){
                if (retrofit==null){
                    retrofit = new Retrofit.Builder().baseUrl(name)
                            .client(new OkHttpClient.Builder()
                                    .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                                    .build())
                            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                }
            }
        }
        return retrofit;
    }
}
